package com.codedancer.campus.manager.api.confessionalWallComment;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codedancer.campus.common.anno.InterfacePermission;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import com.codedancer.campus.manager.api.confessionalWallComment.ro.ConfessionalWallCommentPageSearchRo;
import com.codedancer.campus.manager.service.IConfessionalWallCommentService;
import com.codedancer.campus.manager.service.bo.confessionalWallComment.ConfessionalWallCommentPageSearchBo;
import com.codedancer.campus.manager.service.vo.confessionalWallComment.ConfessionalWallCommentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/confessional-wall-comment")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "表白墙评论Api", description = "表白墙评论Api", tags = "表白墙评论Api")
public class ConfessionalWallCommentApi extends BaseApi {

    @Autowired
    private IConfessionalWallCommentService confessionalWallCommentService;

    @GetMapping("/page/parent-comment/{confessionalWallUuid}")
    @ApiOperation("分页查询表白墙父级评论")
    @InterfacePermission(encodes = {"superAdmin","confessionalWallAdmin"})
    public ApiResponse<IPage<ConfessionalWallCommentVo>> pageParentComment(
        @PathVariable(value = "confessionalWallUuid", required = true) @ApiParam(value = "表白墙uuid", required = true) String confessionalWallUuid,
        @ApiParam(value = "表白墙分页查询Ro", required = false) ConfessionalWallCommentPageSearchRo confessionalWallCommentPageSearchRo) {
        ConfessionalWallCommentPageSearchBo confessionalWallCommentPageSearchBo = BeanUtil
            .copyProperties(confessionalWallCommentPageSearchRo,
                ConfessionalWallCommentPageSearchBo.class);
        confessionalWallCommentPageSearchBo.setConfessionalWallUuid(confessionalWallUuid);
        return success(
            confessionalWallCommentService.pageParentComment(confessionalWallCommentPageSearchBo));
    }

    @GetMapping("/page/children-comment/{confessionalWallCommentUuid}")
    @ApiOperation("分页查询该评论下子集评论")
    @InterfacePermission(encodes = {"superAdmin","confessionalWallAdmin"})
    public ApiResponse<IPage<ConfessionalWallCommentVo>> pageChildrenComment(
        @PathVariable(value = "confessionalWallCommentUuid", required = true) @ApiParam(value = "表白墙评论顶级uuid", required = true) String confessionalWallCommentUuid,
        @ApiParam(value = "表白墙分页查询Ro", required = false) ConfessionalWallCommentPageSearchRo confessionalWallCommentPageSearchRo) {
        ConfessionalWallCommentPageSearchBo confessionalWallCommentPageSearchBo = BeanUtil
            .copyProperties(
                confessionalWallCommentPageSearchRo, ConfessionalWallCommentPageSearchBo.class);
        confessionalWallCommentPageSearchBo
            .setConfessionalWallCommentUuid(confessionalWallCommentUuid);
        return success(confessionalWallCommentService
            .pageChildrenComment(confessionalWallCommentPageSearchBo));
    }

    @DeleteMapping("/delete/{uuid}")
    @ApiOperation("删除评论")
    @InterfacePermission(encodes = {"superAdmin","confessionalWallAdmin"})
    public ApiResponse<Void> delete(
        @PathVariable(value = "uuid", required = true) @ApiParam(value = "表白墙评论uuid", required = true) String uuid) {
        confessionalWallCommentService.delete(uuid);
        return success();
    }
}
